import axios from 'axios'

//获取短网址
interface IgetLine{
  Filter:string,
  Sorting:string,
  SkipCount:number,
  MaxResultCount:number
}
//获取短网址列表
export const getLine=(params:IgetLine):any=>{
  return axios.get("/webapi/api/app/sort-line",{params})
}

//新增短网址
export const addLine=(params:any):any=>{
  return axios.post("/webapi/api/app/sort-line",params)
}

//修改短网址
export const setLine=(id:string,params:any):any=>{
  return axios.put("/webapi/api/app/sort-line/"+id,params)
}

//删除短网址
export const delLine=(id:string):any=>{
  return axios.delete("/webapi/api/app/sort-line/"+id)
}

//获取短网址
export const getLineDetail=(id:string):any=>{
  return axios.get("/webapi/api/app/sort-line/"+id)
}
//重置短网址点击数
export const restLineCount=(id:string):any=>{
  return axios.put(`/webapi/api/app/sort-line/${id}/reset-request-count`)
}


//获取网址
export const getLineUrl=(hash:string,domain:string):any=>{
 return  axios.get(`/webapi/api/app/sort-line/${hash}?domain=${domain}`)
  //  return  `${location.origin}/webapi/api/app/sort-line/${hash}`
}


interface IsetLineDetail{
  "id":string,
  "redirectTargetId":string,
  "target": string,
  "redirectType": number,
  "utmSource"?: string,
  "utmMedium"?: string,
  "utmCampaign"?: string,
  "utmTerm"?: string,
  "utmContent"?: string
}
//新增分流
export const addLineDetail=(id:string,params:IsetLineDetail):any=>{
  return axios.post(`/webapi/api/app/sort-line/${id}/redirect-target`,params)
}
//修改分流
export const setLineDetail=(params:IsetLineDetail):any=>{
  return axios.put(`/webapi/api/app/sort-line/${params.id}/redirect-target/${params.redirectTargetId}`,params)
}
//删除分流
export const delLineDetail=(id:string,redirectTargetId:string):any=>{
  return axios.delete(`/webapi/api/app/sort-line/${id}/redirect-target/${redirectTargetId}`)
}
//开分流
export const switchActive=(id:string,redirectTargetId:string):any=>{
  return axios.put(`/webapi/api/app/sort-line/${id}/redirect-target/${redirectTargetId}/active`)
}
//关分流
export const switchInActive=(id:string,redirectTargetId:string):any=>{
  return axios.put(`/webapi/api/app/sort-line/${id}/redirect-target/${redirectTargetId}/inactive`)
}


//修改tags
interface Itag{
  "tags": [
    string
  ]
}
export const setTags=(id:string,params:Itag):any=>{
  return axios.put(`/webapi/api/app/sort-line/${id}/tags`,params)
}

//限制ip归属地
//修改tags
interface IFilterIpCity{
  isInterceptProxy: Boolean,
  countryFilterMode: Number,
  country: string
}
export const setFilterIpCity=(id:string,params:IFilterIpCity):any=>{
  return axios.put(`/webapi/api/app/sort-line/${id}/set-prohibited`,params)
}

